package com.wdd.myplatform.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wdd.myplatform.utils.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @author wdd 2022/4/21
 */
@RestController
@RequestMapping("/redisPubSubController")
public class RedisPubSubController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/pubMessage/{message}")
    public void pubMessage(@PathVariable("message") String message){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("pubTopic",Constants.REDIS_TOPIC1);
        jsonObject.put("content",message);
        stringRedisTemplate.convertAndSend(Constants.REDIS_TOPIC1,jsonObject.toString());
    }

}
